//
//  LZPaymentAccountTextFieldCell.m
//  laziz_Merchant
//
//  Created by xbnzd on 17/3/7.
//  Copyright © 2017年 XBN. All rights reserved.
//

#import "LZPaymentAccountTextFieldCell.h"

@interface LZPaymentAccountTextFieldCell()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *textFiled;
@property (strong, nonatomic) NSIndexPath *indexP;
@end

@implementation LZPaymentAccountTextFieldCell

- (void)awakeFromNib {
    [super awakeFromNib];

    self.textFiled.delegate = self;
    self.textFiled.tintColor = UIColorFromRGB(0x36bb2a, 1);
}

- (void)loadContent:(NSString *)contentStr placeholder:(NSString *)str indexPath:(NSIndexPath *)indexPath
{
    self.indexP = indexPath;
    self.textFiled.placeholder = str;
    if (contentStr.length != 0) {
        self.textFiled.text = contentStr;
    }
    self.textFiled.keyboardType = UIKeyboardTypeDefault;
    if (indexPath.section == 0) {
        if (indexPath.row == 1) {
            self.textFiled.keyboardType = UIKeyboardTypePhonePad;
        }
    }
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSInteger totalLength = textField.text.length;
    NSInteger replaceLength = string.length;
    
    //字数限制
    if (totalLength + replaceLength > 50) {
        return NO;
    }
    
    if (self.paymentAccountCellDelegate && [self.paymentAccountCellDelegate respondsToSelector:@selector(getContentText: withIndexPath:)]) {
        [self.paymentAccountCellDelegate getContentText:textField.text withIndexPath:self.indexP];
    }
    
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (self.paymentAccountCellDelegate && [self.paymentAccountCellDelegate respondsToSelector:@selector(getContentText: withIndexPath:)]) {
        [self.paymentAccountCellDelegate getContentText:textField.text withIndexPath:self.indexP];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
